<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{margin: 0;padding: 0;}
        .box{
            width: 300px;
            height: 300px;
            background: yellow;
            display: inline-block;
            position: absolute;
        }
        .inner{
            width: 100%;
            height: 30px;
            background: skyblue;
        }
        .inner button{
            border: none;
            height: 30px;
            background: skyblue;
            padding-left: 20px;
        }
    </style>
</head>
<body>
    <div class="box">
        <div class="inner">
            <button class="btn">关闭</button>
        </div>
    </div>
    <script>
        var oBox=document.querySelector(".box");
        var oInner=document.querySelector(".inner");
        var oBtn=document.querySelector(".btn");

        oInner.onmousedown=function(evt){
            var e=evt||window.event;
            var disX=e.pageX-oBox.offsetLeft;
            var disY=e.pageY-oBox.offsetTop;
            document.onmousemove=function(evt){
                var e=evt||window.event;
                oBox.style.left=e.pageX-disX+"px";
                oBox.style.top=e.pageY-disY+"px";
            }
            document.onmouseup=function(){
                document.onmouseup=document.onmousemove=null;
            }
        }
        oBtn.onclick=function(){
            oBox.style.display="none";
        }
    </script>
</body>
</html>